package main

import (
	"fmt"
	"math/rand"
	"time"
)

func insertionSort(arr []int) []int {
	for i, v := range arr {
		preIndex := i - 1
		temp := v
		for preIndex >= 0 && arr[preIndex] > temp {
			arr[preIndex+1] = arr[preIndex]
			preIndex--
		}
		arr[preIndex+1] = temp
	}
	return arr
}

func main() {
	arr := make([]int, 100)
	rand.Seed(time.Now().UnixNano())

	length := len(arr)
	for i := 0; i < length; i++ {
		arr[i] = rand.Intn(1000)
	}
	fmt.Println(arr)
	fmt.Println(insertionSort(arr))
}
